package com.lyp.crm.conrtoller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lyp.crm.entity.Fenye;
import com.lyp.crm.entity.Roles;
import com.lyp.crm.entity.Userroles;
import com.lyp.crm.service.RolesService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Controller
@CrossOrigin(origins = "*")
public class RolesController {
	@Autowired
	private RolesService rolesService;
	@Autowired
	private Fenye<Roles> fenye;
	
	@ApiOperation(value="多条件查询角色", notes="根据 url 的各种数据来获取角色的详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "page", value = "分页参数", required = true, dataType = "Integer", paramType = "path"), 
		@ApiImplicitParam(name = "rows", value = "分页参数", required = true, dataType = "Integer", paramType = "path"), 
		@ApiImplicitParam(name = "rname", value = "角色名称", required = true, dataType = "String", paramType = "path"), 
		@ApiImplicitParam(name = "rjurisdic", value = "角色权限", required = true, dataType = "String", paramType = "path"), 
		
	})
	@RequestMapping(value="/selectRoles",method=RequestMethod.POST)
	@ResponseBody
        public Fenye<Roles> selectRoles(Integer rows,Integer page,Roles roles){
		fenye.setPage((page-1)*rows);
		fenye.setPageSize(rows);
		fenye.setT(roles);
		fenye = rolesService.selectRoles(fenye);
		return fenye;
		
	}
	@ApiOperation(value="多条件查询角色", notes="根据 url 的各种数据来获取角色的详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rname", value = "角色名称", required = true, dataType = "String", paramType = "path"), 
		@ApiImplicitParam(name = "rjurisdic", value = "角色权限", required = true, dataType = "String", paramType = "path"), 
		
	})
	@RequestMapping(value="/selectRoleslist",method=RequestMethod.POST)
	@ResponseBody
        public List<Roles> selectRoleslist(Roles roles){
		return  rolesService.selectRoleslist(roles);
		
	}
	
	@ApiOperation(value="删除角色", notes="根据 url 的rid来删除获取角色的详细信息")
	@ApiImplicitParam(name = "rid", value = "角色id", required = true, dataType = "Integer", paramType = "path")
		
	@RequestMapping(value="/deleteRoles",method=RequestMethod.POST)
	@ResponseBody
    public	Integer deleteRoles(Integer rid){
		Integer byRrid = rolesService.selectdelByRrid(rid);
		if (byRrid==0) {
			return rolesService.deleteRoles(rid);
		} else {
			return 0;
		}
	}
	@ApiOperation(value="修改角色", notes="根据 url 的各种数据来修改角色的详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rid", value = "角色id", required = true, dataType = "Integer", paramType = "path"), 
		@ApiImplicitParam(name = "rname", value = "角色名称", required = true, dataType = "String", paramType = "path"), 
		@ApiImplicitParam(name = "rjurisdic", value = "角色权限", required = true, dataType = "String", paramType = "path"), 
		
	})
	@RequestMapping(value="/updateRoles",method=RequestMethod.POST)
	@ResponseBody
    public	Integer updateRoles(Roles roles){
		return rolesService.updateRoles(roles);
		
	}
	
	@ApiOperation(value="查找我的角色", notes="根据 url 的uid来查找我的角色的详细信息")
	@ApiImplicitParam(name = "uid", value = "用户id", required = true, dataType = "Integer", paramType = "path")
	
	@RequestMapping(value="/myRoleslist",method=RequestMethod.POST)
	@ResponseBody
	public List<Roles> myRoleslist(Integer uid) {
		// TODO Auto-generated method stub
		return rolesService.myRoleslist(uid);
	}
	
	@ApiOperation(value="查询用户角色", notes="根据 url 的各种数据来查询用户角色的详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "uusid", value = "用户id", required = true, dataType = "Integer", paramType = "path"), 
		@ApiImplicitParam(name = "uroid", value = "角色id", required = true, dataType = "Integer", paramType = "path"), 
	})
	@RequestMapping(value="/selectUserroles",method=RequestMethod.POST)
	@ResponseBody
	public Integer selectUserroles(Userroles userroles) {
		return rolesService.selectUserroles(userroles);
	}
	@ApiOperation(value="增加用户角色", notes="根据 url 的各种数据来增加一条用户角色的详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "uusid", value = "用户id", required = true, dataType = "Integer", paramType = "path"), 
		@ApiImplicitParam(name = "uroid", value = "角色id", required = true, dataType = "Integer", paramType = "path"), 
	})
	@RequestMapping(value="/insertUserroles",method=RequestMethod.POST)
	@ResponseBody
	public Integer insertUserroles(Userroles userroles) {
		return rolesService.insertUserroles(userroles);
	}
	@ApiOperation(value="删除用户角色", notes="根据 url 的各种数据来删除一条用户角色的详细信息")
	@ApiImplicitParam(name = "uuid", value = "用户角色id", required = true, dataType = "Integer", paramType = "path")
	@RequestMapping(value="/deleteUserroles",method=RequestMethod.POST)
	@ResponseBody
	public Integer deleteUserroles(Integer uuid) {
		return rolesService.deleteUserroles(uuid);
	}
	
	@ApiOperation(value="增加角色", notes="根据 url 的各种数据来增加一条角色的详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rname", value = "角色名称", required = true, dataType = "String", paramType = "path"), 
		@ApiImplicitParam(name = "rjurisdic", value = "角色权限", required = true, dataType = "String", paramType = "path"), 
	})
	@RequestMapping(value="/insertRoles",method=RequestMethod.POST)
	@ResponseBody
	public Integer insertRoles(Roles roles) {
		Integer rname = rolesService.selectinsertRname(roles);
		if (rname>0) {
			return 0;
		} else {
			return rolesService.insertRoles(roles);
		}
		
	}
	@ApiOperation(value="增加角色模块", notes="根据 url 的各种数据来增加一条角色模块的详细信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "rmrid", value = "角色编号", required = true, dataType = "Integer", paramType = "path"), 
		@ApiImplicitParam(name = "rmmid", value = "模块编号", required = true, dataType = "Integer", paramType = "path"), 
	})
	@RequestMapping(value="/insertRoleModule",method=RequestMethod.POST)
	@ResponseBody
	public Integer insertRoleModule(String rmmid,Integer rmrid) {
		Integer i = rolesService.InsertRolem(rmmid, rmrid);
		return i;
	}
}
